var editor;
$(document).ready(function(){
	var options = {
        filterMode : true,
		width:"678px",
		height:"200px",
		resizeType:0
	};
	
    KindEditor.ready(function(K) {
        editor = K.create('#content',options);
    }); 
    
});    

function sub() {
    var con = 0;
    editor.sync();
    title = $('#title').val();
    content = $('#content').val();
    select = $('#s2').val(); 
    file = $('#file').val();
    
    if (title == "") {
        $('#mes1').html(" 标题不能为空!");
        con++;
    } else {
        $('#mes1').html("");
    }
    
    if (content == "") {
        $('#mes2').html(" 内容不能为空!");
        con++;
    } else {
        $('#mes2').html("");
    }
    
    if (select == "请选择") {
        $('#mes3').html(" 请选择模块!");
        con++;
    } else {
        $('#mes3').html("");
    }
    
    if(select != "下载公告（会员）" && select != "下载公告（非会员）"){        
        if (file == "") {
            $('#mes4').html(" 请上传图片!");
            con++;
        } else {
            res = checkUploadName(file);
            if(res==0){
                $('#mes4').html(" 上传的图片必须以jpg、gif、bmp、png结尾！");
                con++;                
            }else{
                setTimeout("$('#mes4').html('')",100);
                
            }            
        }
    }else{
        $('#mes4').html("");
    }
    
    if (con > 0){
        alert("表单出现错误");
        return false;
    }
};     

function sub2() {
    var con = 0;
    editor.sync();
    title = $('#title').val();
    content = $('#content').val();

    if (title == "") {
        $('#mes1').html(" 标题不能为空!");
        con++;
    } else {
        $('#mes1').html("");
    }
    
    if (content == "") {
        $('#mes2').html(" 内容不能为空!");
        con++;
    } else {
        $('#mes2').html("");
    }
        
    if (con > 0){
        alert("表单出现错误");
        return false;
    }
};     

function sub3() {
    var con = 0;
    editor.sync();
    content = $('#content').val();
    
    if (content == "") {
        alert('回复内容不能为空！');
        return false;
    } 
};  

function checkUploadName(name){
    var isValid=0;
    var suffix =["jpg","gif","bmp","png"]; 
    leng = name.length;    
    var temp = name.substr(leng-3,leng); 
    extension = temp.toLowerCase(); 
    for(i=0;i<suffix.length;i++){
        if (extension==suffix[i]){
            isValid=1;
        }
    }
    return isValid; 
}
